<template>
  <div class="code-example">
    <el-tabs v-model="activeTab" type="card">
      <el-tab-pane label="java" name="0">
        <codeMonitor v-if="activeTab == 0" :value="codeList[0].replace('\n', '')"></codeMonitor>
      </el-tab-pane>
      <el-tab-pane label="python" name="1">
        <codeMonitor v-if="activeTab == 1" :value="codeList[1].replace('\n', '')"></codeMonitor>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>
 
<script>
import codeMonitor from "./codeMonitor.vue";
export default {
  name: "codeExample",
  components: { codeMonitor },
  data: () => ({
    activeTab: 0,
    codeList: [`
  public static void main(String[] args) {
    String url = "http://xxx.com/api-cloud-manage";
    String appkey = "你自己的Appkey";
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("xxx", xxx);
    Map<String, String> params = new HashMap<String, String>();
    params.put("access_token", appkey);
    params.put("xxx", xxxx);
    try {
        HttpClient httpClient = HttpClients.createDefault();
        HttpPost httpPost = new HttpPost(url);
        if (headers != null && headers.size() > 0) {
            Set keySet = headers.keySet();
            for (Object key : keySet) {
                httpPost.addHeader(new BasicHeader((String) key, (String) headers.get(key)));
            }
        }
        List<NameValuePair> paramsList = new ArrayList<NameValuePair>();
        if (params != null && params.size() > 0) {
            Set keySet = params.keySet();
            for (Object key : keySet) {
                paramsList.add(new BasicNameValuePair((String) key, (String) params.get(key)));
            }
        }

        httpPost.setEntity(new UrlEncodedFormEntity(paramsList, "utf-8"));
        HttpResponse response = httpClient.execute(httpPost);
        System.out.println(response.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
  }`,
      `
  appkey =  "你自己的Appkey"
  params = urllib.parse.urlencode({'access_token': appkey, 'xxx': xxx})
  headers = {"Content-type": "application/x-www-form-urlencoded",
              "Accept": "application/json","xxx":xxx}
  conn = http.client.HTTPSConnection("http://xxx.com")
  conn.request("POST", "/api-cloud-manage", params, headers)
  response = conn.getresponse()
  print(response.status, response.reason)

  if not response.closed:
      data = response.read()
      print(data, type(data.decode('utf-8')))
  conn.close()`
    ]
  }),
}
</script>